/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sigmacinema.ui.tapestry.controller;

import com.javaforge.tapestry.spring.annotations.InjectSpring;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.tapestry.annotations.Bean;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.record.PropertyChangeObserver;
import org.apache.tapestry.valid.ValidationDelegate;
import sigmacinema.entity.Authorities;
import sigmacinema.entity.Customer;
import sigmacinema.entity.User;
import sigmacinema.service.SigmaCinemaService;

/**
 *
 * @author amir
 */
public abstract class CustomerController extends BasePage{

    @InjectSpring("SigmaCinemaService")
    public abstract SigmaCinemaService getSigmaCinemaService();
    @Bean
    public abstract ValidationDelegate getDelegate();
    
    private User user = new User();
    private Customer customer = new Customer();
    private Authorities a = new Authorities();
    private List<Authorities> auth = new ArrayList<Authorities>();
    
    public String save(){
        ValidationDelegate delegate = getDelegate();
        if (delegate.getHasErrors()) {
            return null;
        }
        else{
            customer.setUser(user);
            user.setEnabled(1);
            a.setAuthority("ROLE_MEMBER");
            a.setUser(user);
            auth.add(a);

            user.setAuth(auth);
            user.setCustomer(customer);
            getSigmaCinemaService().saveCustomer(user);
            return "Home";
        }
    }

    public List<Authorities> getAuth() {
        return auth;
    }

    public void setAuth(List<Authorities> auth) {
        this.auth = auth;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    @Override
    public String getClientId() {
        return null;
    }

    @Override
    public void setClientId(String string) {
        
    }

    @Override
    public PropertyChangeObserver getPropertyChangeObserver() {
        return null;
    }
    
}
